<?php
    session_start();
    
    if (is_null($_SESSION["g2ulogin"]) || $_SESSION["g2uName"]=="undefined"){
        $_SESSION["g2ulogin"] = 1;
    }
    
    if ($_SESSION["g2ulogin"] == 1) {
        include_once 'portada.html';
    } else {
        if ($_SESSION["g2ulogin"] == 2) {
            if(!isset($_REQUEST["op"])){
                include_once 'principal.php';
            } else {    
                switch ($_REQUEST["op"]) {
                    case "perfil":
                        include_once 'perfil.php';
                    break;
                
                    case "wishlist":
                        include_once 'recursos/funciones.php';
                        $_SESSION["g2uWishlist"] = cargar_wishlist($_SESSION["g2uId"]);
                        $_SESSION["dataWishList"] = $_SESSION["g2uWishlist"];
                        
                        $_SESSION["dataUser"]["g2uId"] = $_SESSION["g2uId"];
                        $_SESSION["dataUser"]["g2uProfilePic"] = $_SESSION["g2uProfilePic"];
                        $_SESSION["dataUser"]["g2uFirstName"] = $_SESSION["g2uFirstName"];
                        $_SESSION["dataUser"]["g2uLastName"] = $_SESSION["g2uLastName"];
                        //$_SESSION["dataUser"] = 
                        include_once 'wishlist.php';
                    break;
                
                    case "friends":
                        include_once 'recursos/funciones.php';
                        $_SESSION["g2uFriendList"] = cargar_friendList($_SESSION["g2uId"]);
                        $_SESSION["g2uFriendInvFBList"] = cargar_friend_inv_fb_list($_SESSION["g2uId"]);
                        //$_SESSION["g2uFriendInvFBList_ext"] = cargar_friend_inv_fb_sent_list($_SESSION["g2uId"]);
                        include_once 'friends.php';
                    break;
                
                    case "eventos":
                        include_once 'recursos/funciones.php';
                        $_SESSION["g2uEventList"] = cargar_eventList($_SESSION["g2uId"]);

                        include_once 'events.php';
                    break;
                
                    case "noticias":
                        include_once 'recursos/funciones.php';
                        $limit = 3;
                        $_SESSION["g2uFriendList"] = cargar_friendList($_SESSION["g2uId"]);
                        
                        $_SESSION["g2uNewsList"] = cargar_newsList($_SESSION["g2uId"], $_SESSION["g2uFriendList"]);
                        $_SESSION["g2uNewsWishList"] = cargar_news_wishlist($_SESSION["g2uId"], $_SESSION["g2uFriendList"]);

                        if(is_array($_SESSION["g2uNewsList"])){
                            foreach ($_SESSION["g2uNewsList"] as $key => $value) {
                                $_SESSION["g2uDataPhotoComment"][$key] = cargar_comentarios($key, $limit);
                            }
                        }
                        
                        
                        include_once 'news.php';
                    break;
                
                    case "event_gral":
                        include_once 'recursos/funciones.php';
                        
                        $_REQUEST["eid"] = str_replace("event_", "", $_REQUEST["eid"]);
                        
                        $_SESSION["g2uFriendList"] = cargar_friendList_event($_REQUEST["eid"]);
                        $_SESSION["g2uNewsList"] = cargar_newsList_event($_SESSION["g2uId"], $_SESSION["g2uFriendList"], $_REQUEST["eid"]);
                        
                        foreach ($_SESSION["g2uNewsList"] as $key => $value) {
                            $_SESSION["g2uDataPhotoComment"][$key] = cargar_comentarios($key);
                        }
                        
                        include_once 'event_gral.php';
                    break;

                    default:
                        include_once 'principal.php';
                        break;
                }
            }
        }
    }
?>